#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Extract groups with numbers of members beneath a certain threshold
#Usage: gfliter.pl <groupdir> <newgroupdir> <threshold>

my $groupdir = shift;
my $newdir = shift;
my $threshold = shift;
mkdir $newdir;
foreach my $file (`ls $groupdir`) {
	chomp $file;
	my $cnt = `grep ">" $groupdir/$file | wc -l`;
	chomp $cnt;
#	print "$file: " . $cnt . "\n";
	if ($cnt < $threshold) {
		print $file . "\n";
		`cp $file.fasta.splice $newdir`;
#		`cp $groupdir/$file $newdir/$file`;
	}
}
